<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%@ include file="../../header.jsp" %>
</head>
<body>

 <form id="formUpd" class="layui-form">
 


 <div class="layui-form-item">
   
     <label class="layui-form-label"></label>
        <div class="layui-input-block"> 
        </div>
 </div>
 <div class="layui-form-item">
   
     <label class="layui-form-label">学号</label>
        <div class="layui-input-block"> 
        <input type= "text" id="studentId" readonly value='<%=request.getParameter("id") %>' class="layui-input" style="width: 150px;"></input>
        </div>
 </div>
 

 
<div class="layui-form-item">
   <label class ="layui-form-label">姓名</label>
   <div class="layui-input-block">
   <input type="text" id="studentName" value='<%=request.getParameter("name")%>'  class="layui-input" style="width:150px">
   
   </div>
   
</div>
<div class="layui-form-item">
   <label class ="layui-form-label">年龄</label>
   <div class="layui-input-block">
   <input type="text" id="age"  value=<%=request.getParameter("age")%> class="layui-input" style="width:150px">
   
   </div>
  </div> 
   
  <div class="layui-form-item">
   <label class ="layui-form-label">性别</label>
   <div class="layui-input-block">
   <input type="text" id="studentSex" value= "<%=request.getParameter("sex") %>"  class="layui-input" style="width:150px">
   
   </div>
  <input  type="hidden" id="courseChecked" value="<%=request.getParameter("courseId") %>">

</div>

 	 <div class="layui-form-item" id ="选课信息">
		<label class="layui-form-label">选课信息</label>
		<div class="layui-input-block" id="courseIdd" >
			
			
		</div>
	</div>	



  <div class="layui-form-itme">
   <div class="layui-input-block">
   <input type="javascript:;"  class="layui-btn" onclick="close()" value="关闭" style="width:80px" ></input>
   <button type="reset"  title="重置"  class="layui-btn">重置</button>
     <input  type="hidden" id="selectId" value = "查询" onclick="select1()" style="width:80px"  class="layui-btn"></input>
     <input name ="action" type="button"  value = "修改" onclick="update()" style="width:80px"  class="layui-btn"></input>
  
   </div>
   
   
</div>


 </form>

</body>

</body>

<script src="../../static/js/base.js"></script>
<script type="text/javascript">
element.render();
function select1(){
	 
	var courseChecked = $("#courseChecked").val();
	
	
	ajax("/StudentMangers/CourseServlet",{action:"查询课程"},"json",function(data){
		
		    
		
		     var optc =""
		     
			
			  
			
			     $.each(data,function(i,dom){
			    	
			    	var course = dom.courseName +" ("+dom.courseId+")";
			    	if(courseChecked.indexOf(dom.courseId)!=-1){
				    	optc += '<input type="checkbox"  title="'+course+'" name="course_name"  value="'+dom.courseId+'" checked  name="courseIdd">'

			    	}else{
			    	optc += '<input type="checkbox"  title="'+course+'" name="course_name"  value="'+dom.courseId+'" name="courseIdd" >'
			    	
			    	}
			     })
			     
			     $("#courseIdd").html(optc);
			 
		       form.render();
	})
	
	
}


refresh();

function refresh(){
	 $("#selectId").click();	
	}
function update(){
	var id = $("#studentId").val();
	var name = $("#studentName").val();
	var age = $("#age").val();
	var sex = $("#studentSex").val();
	var courseIds = $("input[name='course_name']");
   
   var courseId="";
	for (var i = 0; i < courseIds.length; i++) {
		if (courseIds[i].checked == true) {

			courseId += courseIds[i].value + " ";


		}

	}


ajax("/StudentMangers/StudentServlet",{action:"修改",studentId:id,studentName:name,age:age,studentSex:sex,courseId:courseId},"json",function(data){
	
	if(data=="1"){

		layer.msg("修改成功",close);
		
		
	}else{
		layer.msg("修改失败");
	}
	
});
}





function refresh(){
	 $("#selectId").click();	
	}

   
</script>
</html>